import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: user
 * Date: 2024-04-20
 * Time: 16:07
 */
class IntCmp implements Comparator<Integer>{
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}
public class Test {

    public int[] smallestK(int[] arr, int k) {
      PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new IntCmp());
      int[] ret = new int[k];
        for (int i = 0; i < k; i++) {
            priorityQueue.offer(arr[i]);
        }
        for (int j = k; j < arr.length; j++) {
            if(arr[j] < priorityQueue.peek()){
                priorityQueue.poll();
                priorityQueue.offer(arr[j]);
            }
        }
        for (int i = 0; i < ret.length; i++) {
            ret[i] = priorityQueue.poll();
        }
      return ret ;
    }
    public static void main(String[] args) {

    }
    public static void main1(String[] args) {
      int[] array = {27,15,19,18,28,34,65,49,25,37};
      MyHeap myHeap = new MyHeap();
      myHeap.init(array);
      myHeap.createHeap();
      myHeap.offer(51);
      myHeap.offer(59);
      myHeap.offer(89);
      myHeap.heapSort();
        System.out.println(myHeap.poll());
        System.out.println(myHeap.poll());
        System.out.println(myHeap.poll());
    }
}
